package entity.CRM;

import entity.FRM.CashInAdvance;
import entity.FRM.CustomerInvoice;
import entity.FRM.CustomerPayment;
import entity.SCM.DeliveryOrder;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;


@Entity
public class SaleOrder implements Serializable {
    public enum StateSaleOrder {Pending, Confirmed, Completed, Canceled}
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String saleOrderDate;
    private StateSaleOrder stateSaleOrder;
    
    @ManyToOne
    private Customer customer;
    @ManyToOne
    private SaleQuotation saleQuotation;
    @OneToMany
    private List<LineItem> lineItems = new ArrayList<LineItem>();
    @OneToOne
    private CashInAdvance cashInAdvance;
    @OneToMany
    private List<CustomerInvoice> customerInvoices = new ArrayList<CustomerInvoice>();
    @OneToMany
    private List<CustomerPayment> customerPayments = new ArrayList<CustomerPayment>();
    @OneToMany
    private List<DeliveryOrder> deliveryOrders = new ArrayList<DeliveryOrder>();

    public StateSaleOrder getStateSaleOrder() {
        return stateSaleOrder;
    }

    public void setStateSaleOrder(StateSaleOrder stateSaleOrder) {
        this.stateSaleOrder = stateSaleOrder;
    }
    
    
    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<LineItem> getLineItems() {
        return lineItems;
    }

    public void setLineItems(List<LineItem> lineItems) {
        this.lineItems = lineItems;
    }

    public String getSaleOrderDate() {
        return saleOrderDate;
    }

    public void setSaleOrderDate(String saleOrderDate) {
        this.saleOrderDate = saleOrderDate;
    }

    public SaleQuotation getSaleQuotation() {
        return saleQuotation;
    }

    public void setSaleQuotation(SaleQuotation saleQuotation) {
        this.saleQuotation = saleQuotation;
    }

    public CashInAdvance getCashInAdvance() {
        return cashInAdvance;
    }

    public void setCashInAdvance(CashInAdvance cashInAdvance) {
        this.cashInAdvance = cashInAdvance;
    }


    public List<CustomerInvoice> getCustomerInvoices() {
        return customerInvoices;
    }

    public void setCustomerInvoices(List<CustomerInvoice> customerInvoices) {
        this.customerInvoices = customerInvoices;
    }
    
    
    public Double getTotalPrice()
    {
        Double temp=0.0;
        for (LineItem e:this.getLineItems())
        {
            temp+=e.getFinalPrice();
        }
        return temp;
    }

    public List<DeliveryOrder> getDeliveryOrders() {
        return deliveryOrders;
    }

    public void setDeliveryOrders(List<DeliveryOrder> deliveryOrders) {
        this.deliveryOrders = deliveryOrders;
    }

    public List<CustomerPayment> getCustomerPayments() {
        return customerPayments;
    }

    public void setCustomerPayments(List<CustomerPayment> customerPayments) {
        this.customerPayments = customerPayments;
    }
    
    
}
